package com.caine.auth.config;

import com.caine.common.tool.RSATool;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @Author: CaineZhu
 * @Description:
 * @Date: Created in 16:11 2021/1/7
 * @Modified By:
 */
@Data
@ConfigurationProperties(prefix = "jwt.rsa")
public class RsaKeyProperties {
    private String pubKey;
    private String priKey;

    private PublicKey publicKey;
    private PrivateKey privateKey;

    /**
     * 系统启动的时候触发
     * @throws Exception
     */
    @PostConstruct
    public void createRsaKey() throws Exception {
        publicKey = RSATool.getPublicKeyFromStr(pubKey);
        privateKey = RSATool.getPrivateKeyFromStr(priKey);
    }
}
